<!DOCTYPE html>
<html lang="en">
<head>
    <title>初始化</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" type="text/css" href="/plugins/layui-v2.3.0/layui/css/layui.css">
    <script type="text/javascript" src="/plugins/jquery/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/plugins/layui-v2.3.0/layui/layui.all.js"></script>
    <script type="text/javascript" src="/plugins/html2canvas.js"></script>
    <script type="text/javascript" src="/plugins/jspdf.min.js"></script>
    <script type="text/javascript" src="/plugins/canvas2image.js"></script>
    <script type="text/javascript" src="/util/Request.js"></script>
    <style type="text/css">
        .layui-input{
            width: 50%;
        }
        .layui-form-item{
            padding-left: 30%;
        }
    </style>
</head>
<body>
    <div style="margin-top: 40px;" id="indexId">
        <form id="carAuditDetail-form" class="layui-form" lay-filter="carAuditDetail-form">
            <div class="layui-form-item">
                <label class="layui-form-label">组名</label>
                <div class="layui-input-block">
                    <input type="text" name="aliasName" lay-verify="required" autocomplete="on" placeholder="请输入组名"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>源数据库</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">url</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceUrl" lay-verify="required" autocomplete="off" placeholder="请输入URL"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceUser" lay-verify="required" autocomplete="off" placeholder="请输入用户"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" name="sourcePassword" lay-verify="required" autocomplete="off" placeholder="请输入密码"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>目标数据库</legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label">url</label>
                <div class="layui-input-block">
                    <input type="text" name="targetUrl" lay-verify="required" autocomplete="off" placeholder="请输入URL"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户</label>
                <div class="layui-input-block">
                    <input type="text" name="targetUser" lay-verify="required" autocomplete="off" placeholder="请输入用户"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" name="targetPassword" lay-verify="required" autocomplete="off" placeholder="请输入密码"
                           class="layui-input" oninput="this.value=this.value.replace(/^\s+|\s+$/g, '')">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="databases" style="margin-left: 5%">立即提交</button>

                    <button type="reset" class="layui-btn layui-btn-primary" style="margin-left: 12%">重置</button>
                </div>
            </div>
        </form>
    </div>
</body>

<script>
    $.get('/dbs', function (data) {
        if (data.code === 200) {
            console.log(data);
            if (data.data && data.data.length > 0) {
                window.location.href = "pages/home/home.html";
            }
            layui.element.render('nav', 'databases');
            return data.data;
        }else {
            layer.msg('显示数据库错误');
        }
    });
    layui.form.on('submit(databases)', function(data){
        ReqUtils.req('/initDB', 'post', JSON.stringify(data.field)).then(res=>{
            console.log(res);
            if (res.code == 200) {
                window.location.href = "pages/home/home.html";
            }else {
                layer.msg('连接失败，'+data.msg);
            }
        })
        return false;
    });
</script>
</html>